#include "stdio.h"
#include "stdlib.h"

#pragma region 基础结构
typedef struct node
{
    int data;
    struct node *next;
} StackNode, *LinkStack;
#pragma endregion

#pragma region 【算法2 - 23】判栈空算法
int Empty_LinkStack(LinkStack top)
{
    if (top == NULL)
        return 1;
    else
        return 0;
}
#pragma endregion

#pragma region 【算法2 - 24】入栈算法
LinkStack Push_LinkStack(LinkStack top, int x)
{
    StackNode *p;
    p = (StackNode *)malloc(sizeof(StackNode));
    p->data = x;
    p->next = top;
    top = p;
    return top;
}
#pragma endregion
#pragma region 【算法2 - 25】出栈算法
LinkStack Pop_LinkStack(LinkStack top, int *x)
{
    StackNode *p;
    if (top == NULL)
        return NULL;
    else
    {
        *x = top->data;
        p = top;
        top = top->next;
        free(p);
        return top;
    }
}
#pragma endregion

